import { notification } from 'antd';

type ToastType = 'success' | 'warning' | 'error' | 'info';
interface IToast {
    (content: string, title?: string): void;
    success(content: string, title?: string): void;
    warning(content: string, title?: string): void;
    error(content: string, title?: string): void;
};

function topNotice(title: string | undefined, content: string, type: ToastType) {
    notification[type]({
        message: title || '提示',
        description: content,
        placement: 'top',
        duration: 2
    });
}

export const toast: IToast = (content: string, title?: string) => {
    topNotice(title, content, 'info');
};
toast.success = (content: string, title?: string) => {
    topNotice(title, content, 'success');
};
toast.warning = (content: string, title?: string) => {
    topNotice(title, content, 'warning');
};
toast.error = (content: string, title?: string) => {
    topNotice(title, content, 'error');
};

